package com.demo.common;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * Ajax响应结果
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class AjaxResult {
    private Integer code;

    private String msg;

    private Object data;

    public static AjaxResult success() {
        return new AjaxResult(Constants.AJAX_SUCCESS, "success", null);
    }

    public static AjaxResult success(Object data) {
        return new AjaxResult(Constants.AJAX_SUCCESS, "success", data);
    }

    public static AjaxResult success(String msg, Object data) {
        return new AjaxResult(Constants.AJAX_SUCCESS, msg, data);
    }

    public static AjaxResult error() {
        return new AjaxResult(Constants.AJAX_SERVER_ERROR, "系统错误", null);
    }

    public static AjaxResult error(String msg) {
        return new AjaxResult(Constants.AJAX_SERVER_ERROR, msg, null);
    }

    public static AjaxResult error(Integer code, String msg) {
        return new AjaxResult(code, msg, null);
    }

}
